package sdufe.lele.dao;


import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sdufe.lele.model.Financial;
import sdufe.lele.model.Financial2user;

import java.math.BigDecimal;
import java.util.ArrayList;

@Repository
@Mapper
public interface FinancialMapper {

    @Select("select * from financial  limit #{down},#{up}")
    @Results({
            @Result(id = true, column = "financialId", property = "financialid"),
            @Result(column = "financialName", property = "financialname"),
            @Result(column = "financialCycle", property = "financialcycle"),
            @Result(column = "financialRate", property = "financialrate")
    })
    ArrayList<Financial> selectByPage(@Param("down") Integer pageDown, @Param("up") Integer pageUp);


    @Insert("insert into financial2user (userPhone,financialId,balance,broker,description,financialName,createTime,endTime,cycle,currentBalance) values (#{userphone},#{fuid},#{balance},#{broker},#{description},#{financialname},#{createtime},#{endtime},#{cycle},#{currentbalance})")
    int insert_product(Financial2user financial2user);

    @Select("select * from financial where financialId = #{id} ")
    Financial selectFinancialById(Integer id);


    @Select("select * from financial2user  where userPhone = #{phone} limit  #{up},#{down} ")
    @Results({
            @Result(id = true, column = "fuId", property = "fuid"),
            @Result(column = "userPhone", property = "userphone"),
            @Result(column = "financialId", property = "financialid"),
            @Result(column = "balance", property = "balance"),
            @Result(column = "createTime", property = "createtime"),
            @Result(column = "description", property = "description"),
            @Result(column = "broker", property = "broker"),
            @Result(column = "financialName", property = "financialname"),
            @Result(column = "endTime", property = "endtime"),
            @Result(column = "cycle", property = "cycle"),

    })
    ArrayList<Financial2user> selectAllByPhone(@Param("phone") String phone,@Param("up") Integer up,@Param("down") Integer down);

    @Select("select * from financial2user where current_timestamp  < endTime")
    @Results({
            @Result(id = true, column = "fuId", property = "fuid"),
            @Result(column = "userPhone", property = "userphone"),
            @Result(column = "financialId", property = "financialid"),
            @Result(column = "balance", property = "balance"),
            @Result(column = "createTime", property = "createtime"),
            @Result(column = "description", property = "description"),
            @Result(column = "broker", property = "broker"),
            @Result(column = "financialName", property = "financialname"),
            @Result(column = "endTime", property = "endtime"),
            @Result(column = "cycle", property = "cycle"),

    })
    ArrayList<Financial2user> selectVaild();



    @Update("update financial2user set currentBalance = #{current} where fuId = #{id}")
    int updataCurrentBalance(@Param("id") Integer id,@Param("current")BigDecimal current);


}
